package com.enjoyor.soa.traffic.server.efoms.helper;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.enjoyor.soa.traffic.util.helper.FileToStreamHelp;


public class InputStreamToStringHelper {
 
    public static String getStringStream(String ftpHost, String ftpUserName, String ftpPassword, int ftpPort,
            String ftpPath, String fileName)throws Exception {
    	InputStream ins = null;
    	 StringBuilder builder = null;
    	try {
            // 从服务器上读取指定的文件
        	try {
        		ins = FileToStreamHelp.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath,fileName);
			} catch (Exception e) {
				// TODO: handle exception
				throw e;
			}
            BufferedReader reader = new BufferedReader(new InputStreamReader(ins, "UTF-8"));
            String line;
            builder = new StringBuilder(150);
            while ((line = reader.readLine()) != null) {
//                System.out.println(line);
                builder.append(line);
            }
            reader.close();
            if (ins != null) {
                ins.close();
            }
            // 主动调用一次getReply()把接下来的226消费掉. 这样做是可以解决这个返回null问题
            //ftpClient.getReply();
        } catch (Exception e) {
            e.printStackTrace();
        }
    	String aString = builder.toString();
    	return aString;
    	//System.out.println("----------------------------"+aString+"----------------------");
    }
}

